/*      */ package dm.sql;
/*      */ 
/*      */ import dm.jdbc.dataConvertion.Convertion;
/*      */ import dm.jdbc.dbaccess.DBError;
/*      */ import dm.jdbc.util.StringUtil;
/*      */ import java.sql.SQLException;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class DmdbIntervalDT
/*      */   implements Cloneable
/*      */ {
/*      */   public static final byte QUA_D = 3;
/*      */   public static final byte QUA_DH = 4;
/*      */   public static final byte QUA_DHM = 5;
/*      */   public static final byte QUA_DHMS = 6;
/*      */   public static final byte QUA_H = 7;
/*      */   public static final byte QUA_HM = 8;
/*      */   public static final byte QUA_HMS = 9;
/*      */   public static final byte QUA_M = 10;
/*      */   public static final byte QUA_MS = 11;
/*      */   public static final byte QUA_S = 12;
/*   53 */   private byte[] dt = new byte[24];
/*      */   
/*   55 */   public byte type = 3;
/*      */   
/*   57 */   private int loadPrec = 2;
/*   58 */   private boolean isLoadPrecSet = false;
/*      */   
/*   60 */   private int secPrec = 6;
/*   61 */   private boolean isSecPrecSet = false;
/*      */   
/*   63 */   private boolean m_negative = false;
/*      */   
/*   65 */   public int days = 0;
/*      */   
/*   67 */   public int hours = 0;
/*      */   
/*   69 */   public int minutes = 0;
/*      */   
/*   71 */   public int seconds = 0;
/*      */   
/*   73 */   public int fraction = 0;
/*      */   
/*   75 */   private int precForSvr = 0;
/*      */   
/*      */   public final Object clone() {
/*   78 */     DmdbIntervalDT o = null;
/*      */     try {
/*   80 */       o = (DmdbIntervalDT)super.clone();
/*   81 */       if (this.dt != null)
/*   82 */         o.dt = ((byte[])this.dt.clone());
/*      */     } catch (CloneNotSupportedException e) {
/*   84 */       e.printStackTrace();
/*      */     }
/*   86 */     return o;
/*      */   }
/*      */   
/*      */   public int hashCode() {
/*   90 */     return getDTString().hashCode();
/*      */   }
/*      */   
/*      */   public boolean equals(Object o) {
/*   94 */     if ((o != null) && ((o instanceof DmdbIntervalDT))) {
/*   95 */       DmdbIntervalDT tm = (DmdbIntervalDT)o;
/*      */       
/*   97 */       if (tm.type == this.type) {
/*   98 */         switch (this.type) {
/*      */         case 3: 
/*  100 */           if (this.days == tm.days)
/*  101 */             return true;
/*      */           break;
/*      */         case 4: 
/*  104 */           if ((this.days == tm.days) && (this.hours == tm.hours))
/*  105 */             return true;
/*      */           break;
/*      */         case 5: 
/*  108 */           if ((this.days == tm.days) && (this.hours == tm.hours) && 
/*  109 */             (this.minutes == tm.minutes))
/*  110 */             return true;
/*      */           break;
/*      */         case 6: 
/*  113 */           if ((this.days == tm.days) && (this.hours == tm.hours) && 
/*  114 */             (this.minutes == tm.minutes) && 
/*  115 */             (this.seconds == tm.seconds) && 
/*  116 */             (getMsecString().equals(tm.getMsecString())))
/*  117 */             return true;
/*      */           break;
/*      */         case 7: 
/*  120 */           if (this.hours == tm.hours)
/*  121 */             return true;
/*      */           break;
/*      */         case 8: 
/*  124 */           if ((this.hours == tm.hours) && (this.minutes == tm.minutes))
/*  125 */             return true;
/*      */           break;
/*      */         case 9: 
/*  128 */           if ((this.hours == tm.hours) && (this.minutes == tm.minutes) && 
/*  129 */             (this.seconds == tm.seconds) && 
/*  130 */             (getMsecString().equals(tm.getMsecString())))
/*  131 */             return true;
/*      */           break;
/*      */         case 10: 
/*  134 */           if (this.minutes == tm.minutes)
/*  135 */             return true;
/*      */           break;
/*      */         case 11: 
/*  138 */           if ((this.minutes == tm.minutes) && 
/*  139 */             (this.seconds == tm.seconds) && 
/*  140 */             (getMsecString().equals(tm.getMsecString())))
/*  141 */             return true;
/*      */           break;
/*      */         case 12: 
/*  144 */           if ((this.seconds == tm.seconds) && 
/*  145 */             (getMsecString().equals(tm.getMsecString()))) {
/*  146 */             return true;
/*      */           }
/*      */           break;
/*      */         }
/*      */         
/*      */       }
/*      */     }
/*  153 */     return false;
/*      */   }
/*      */   
/*      */   public int getPrecForSvr()
/*      */   {
/*  158 */     return this.precForSvr;
/*      */   }
/*      */   
/*      */   public DmdbIntervalDT(byte[] interval, int loadPre, int secPre) {
/*  162 */     this.dt = interval;
/*  163 */     this.loadPrec = loadPre;
/*  164 */     this.secPrec = secPre;
/*  165 */     this.type = this.dt[21];
/*      */     
/*  167 */     switch (this.type) {
/*      */     case 3: 
/*  169 */       this.days = getDay();
/*  170 */       break;
/*      */     
/*      */     case 4: 
/*  173 */       this.days = getDay();
/*  174 */       this.hours = getHour();
/*  175 */       break;
/*      */     
/*      */     case 5: 
/*  178 */       this.days = getDay();
/*  179 */       this.hours = getHour();
/*  180 */       this.minutes = getMinute();
/*  181 */       break;
/*      */     
/*      */     case 6: 
/*  184 */       this.days = getDay();
/*  185 */       this.hours = getHour();
/*  186 */       this.minutes = getMinute();
/*  187 */       this.seconds = getSecond();
/*  188 */       this.fraction = getMsec();
/*  189 */       break;
/*      */     
/*      */     case 7: 
/*  192 */       this.hours = getHour();
/*  193 */       break;
/*      */     
/*      */     case 8: 
/*  196 */       this.hours = getHour();
/*  197 */       this.minutes = getMinute();
/*  198 */       break;
/*      */     
/*      */     case 9: 
/*  201 */       this.hours = getHour();
/*  202 */       this.minutes = getMinute();
/*  203 */       this.seconds = getSecond();
/*  204 */       this.fraction = getMsec();
/*  205 */       break;
/*      */     
/*      */     case 10: 
/*  208 */       this.minutes = getMinute();
/*  209 */       break;
/*      */     
/*      */     case 11: 
/*  212 */       this.minutes = getMinute();
/*  213 */       this.seconds = getSecond();
/*  214 */       this.fraction = getMsec();
/*  215 */       break;
/*      */     
/*      */     case 12: 
/*  218 */       this.seconds = getSecond();
/*  219 */       this.fraction = getMsec();
/*      */     }
/*      */     
/*      */     
/*  223 */     this.precForSvr = Convertion.getInt(this.dt, 20);
/*      */   }
/*      */   
/*      */   public DmdbIntervalDT(String str) throws SQLException {
/*  227 */     parseIntervDTString(str);
/*      */   }
/*      */   
/*      */   public DmdbIntervalDT(String str, int loadPre, int secPre)
/*      */     throws SQLException
/*      */   {
/*  233 */     this.loadPrec = loadPre;
/*  234 */     this.secPrec = secPre;
/*  235 */     this.isLoadPrecSet = true;
/*  236 */     this.isSecPrecSet = true;
/*      */     
/*  238 */     parseIntervDTString(str);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private void setDay(String value)
/*      */   {
/*  251 */     this.type = 3;
/*  252 */     value = value.substring(1, value.length() - 1);
/*  253 */     int i = Integer.parseInt(value);
/*  254 */     if (this.m_negative) {
/*  255 */       i *= -1;
/*      */     }
/*  257 */     this.days = i;
/*      */   }
/*      */   
/*      */   private void setHour(String value) {
/*  261 */     this.type = 7;
/*  262 */     value = value.substring(1, value.length() - 1);
/*  263 */     int i = Integer.parseInt(value);
/*  264 */     if (this.m_negative) {
/*  265 */       i *= -1;
/*      */     }
/*  267 */     this.hours = i;
/*      */   }
/*      */   
/*      */   private void setMinute(String value) throws SQLException {
/*  271 */     this.type = 10;
/*  272 */     value = value.substring(1, value.length() - 1);
/*  273 */     int i = Integer.parseInt(value);
/*  274 */     if (this.m_negative) {
/*  275 */       i *= -1;
/*      */     }
/*  277 */     this.minutes = i;
/*      */   }
/*      */   
/*      */   private void setSecond(String value) {
/*  281 */     this.type = 12;
/*  282 */     value = value.substring(1, value.length() - 1);
/*  283 */     String[] list = StringUtil.split(value, ".");
/*  284 */     int i = Integer.parseInt(list[0]);
/*  285 */     if (this.m_negative) {
/*  286 */       i *= -1;
/*      */     }
/*  288 */     int nano = 0;
/*  289 */     if (list.length > 1) {
/*  290 */       StringBuffer strNano = new StringBuffer(10);
/*  291 */       strNano.append("0");
/*  292 */       strNano.append(".");
/*  293 */       strNano.append(list[1]);
/*  294 */       double d_v = Double.valueOf(strNano.toString()).doubleValue();
/*  295 */       int nx = (int)Math.pow(10.0D, this.secPrec);
/*  296 */       nano = (int)(d_v * nx);
/*      */     }
/*      */     
/*  299 */     this.seconds = i;
/*  300 */     this.fraction = nano;
/*      */   }
/*      */   
/*      */   private void setHourToSecond(String value) {
/*  304 */     this.type = 9;
/*  305 */     value = value.substring(1, value.length() - 1);
/*  306 */     String[] list = StringUtil.split(value, ":.");
/*      */     
/*  308 */     int h = Integer.parseInt(list[0]);
/*  309 */     if (this.m_negative) {
/*  310 */       h *= -1;
/*      */     }
/*  312 */     int m = Integer.parseInt(list[1]);
/*  313 */     int s = Integer.parseInt(list[2]);
/*  314 */     int nano = 0;
/*  315 */     if (list.length > 3) {
/*  316 */       StringBuffer strNano = new StringBuffer(10);
/*  317 */       strNano.append("0");
/*  318 */       strNano.append(".");
/*  319 */       strNano.append(list[3]);
/*  320 */       double d_v = Double.valueOf(strNano.toString()).doubleValue();
/*  321 */       int nx = (int)Math.pow(10.0D, this.secPrec);
/*  322 */       nano = (int)(d_v * nx);
/*      */     }
/*      */     
/*  325 */     this.hours = h;
/*  326 */     this.minutes = m;
/*  327 */     this.seconds = s;
/*  328 */     this.fraction = nano;
/*      */   }
/*      */   
/*      */   private void setHourToMinute(String value) {
/*  332 */     this.type = 8;
/*      */     
/*  334 */     value = value.substring(1, value.length() - 1);
/*  335 */     String[] list = StringUtil.split(value, ":");
/*      */     
/*  337 */     int h = Integer.parseInt(list[0]);
/*  338 */     if (this.m_negative) {
/*  339 */       h *= -1;
/*      */     }
/*  341 */     int m = Integer.parseInt(list[1]);
/*      */     
/*  343 */     this.hours = h;
/*  344 */     this.minutes = m;
/*      */   }
/*      */   
/*      */   private void setMinuteToSecond(String value) throws SQLException {
/*  348 */     this.type = 11;
/*      */     
/*  350 */     value = value.substring(1, value.length() - 1);
/*  351 */     String[] list = StringUtil.split(value, ":.");
/*      */     
/*  353 */     int m = Integer.parseInt(list[0]);
/*  354 */     if (this.m_negative) {
/*  355 */       m *= -1;
/*      */     }
/*  357 */     int s = Integer.parseInt(list[1]);
/*  358 */     int nano = 0;
/*  359 */     if (list.length > 2) {
/*  360 */       StringBuffer strNano = new StringBuffer(10);
/*  361 */       strNano.append("0");
/*  362 */       strNano.append(".");
/*  363 */       strNano.append(list[2]);
/*  364 */       double d_v = Double.valueOf(strNano.toString()).doubleValue();
/*  365 */       int nx = (int)Math.pow(10.0D, this.secPrec);
/*  366 */       nano = (int)(d_v * nx);
/*      */     }
/*      */     
/*  369 */     this.minutes = m;
/*  370 */     this.seconds = s;
/*  371 */     this.fraction = nano;
/*      */   }
/*      */   
/*      */   private void setDayToHour(String value) {
/*  375 */     this.type = 4;
/*      */     
/*  377 */     value = value.substring(1, value.length() - 1);
/*  378 */     String[] list = StringUtil.split(value, " ");
/*      */     
/*  380 */     int d = Integer.parseInt(list[0]);
/*  381 */     if (this.m_negative) {
/*  382 */       d *= -1;
/*      */     }
/*  384 */     int h = Integer.parseInt(list[1]);
/*      */     
/*  386 */     this.days = d;
/*  387 */     this.hours = h;
/*      */   }
/*      */   
/*      */   private void setDayToMinute(String value) {
/*  391 */     this.type = 5;
/*      */     
/*  393 */     value = value.substring(1, value.length() - 1);
/*  394 */     String[] list = StringUtil.split(value, ": ");
/*      */     
/*  396 */     int d = Integer.parseInt(list[0]);
/*  397 */     if (this.m_negative) {
/*  398 */       d *= -1;
/*      */     }
/*  400 */     int h = Integer.parseInt(list[1]);
/*  401 */     int m = Integer.parseInt(list[2]);
/*      */     
/*  403 */     this.days = d;
/*  404 */     this.hours = h;
/*  405 */     this.minutes = m;
/*      */   }
/*      */   
/*      */   private void setDayToSecond(String value) {
/*  409 */     this.type = 6;
/*      */     
/*  411 */     value = value.substring(1, value.length() - 1);
/*  412 */     String[] list = StringUtil.split(value, ": .");
/*      */     
/*  414 */     int d = Integer.parseInt(list[0]);
/*  415 */     if (this.m_negative) {
/*  416 */       d *= -1;
/*      */     }
/*  418 */     int h = Integer.parseInt(list[1]);
/*  419 */     int m = Integer.parseInt(list[2]);
/*  420 */     int s = Integer.parseInt(list[3]);
/*  421 */     int nano = 0;
/*  422 */     if (list.length > 4) {
/*  423 */       StringBuffer strNano = new StringBuffer(10);
/*  424 */       strNano.append("0");
/*  425 */       strNano.append(".");
/*  426 */       strNano.append(list[4]);
/*  427 */       double d_v = Double.valueOf(strNano.toString()).doubleValue();
/*  428 */       int nx = (int)Math.pow(10.0D, this.secPrec);
/*  429 */       nano = (int)(d_v * nx);
/*      */     }
/*      */     
/*  432 */     this.days = d;
/*  433 */     this.hours = h;
/*  434 */     this.minutes = m;
/*  435 */     this.seconds = s;
/*  436 */     this.fraction = nano;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public final int getDay()
/*      */   {
/*  448 */     byte[] bs = new byte[4];
/*  449 */     System.arraycopy(this.dt, 0, bs, 0, 4);
/*  450 */     int i = Convertion.fourByteToInt(bs);
/*  451 */     return i;
/*      */   }
/*      */   
/*      */   public final int getHour() {
/*  455 */     byte[] bs = new byte[4];
/*  456 */     System.arraycopy(this.dt, 4, bs, 0, 4);
/*  457 */     int i = Convertion.fourByteToInt(bs);
/*  458 */     return i;
/*      */   }
/*      */   
/*      */   public final int getMinute() {
/*  462 */     byte[] bs = new byte[4];
/*  463 */     System.arraycopy(this.dt, 8, bs, 0, 4);
/*  464 */     int i = Convertion.fourByteToInt(bs);
/*  465 */     return i;
/*      */   }
/*      */   
/*      */   public final int getSecond() {
/*  469 */     byte[] bs = new byte[4];
/*  470 */     System.arraycopy(this.dt, 12, bs, 0, 4);
/*  471 */     int i = Convertion.fourByteToInt(bs);
/*  472 */     return i;
/*      */   }
/*      */   
/*      */   public final int getMsec() {
/*  476 */     byte[] bs = new byte[4];
/*  477 */     System.arraycopy(this.dt, 16, bs, 0, 4);
/*  478 */     int tmp = Convertion.fourByteToInt(bs);
/*  479 */     return tmp;
/*      */   }
/*      */   
/*      */   public final byte getDTType() {
/*  483 */     return this.type;
/*      */   }
/*      */   
/*      */   public final int getSecPrec() {
/*  487 */     return this.secPrec;
/*      */   }
/*      */   
/*      */   public final int getLoadPrec() {
/*  491 */     return this.loadPrec;
/*      */   }
/*      */   
/*      */   public final int abs(int i) {
/*  495 */     if (i < 0) {
/*  496 */       i = -i;
/*      */     }
/*  498 */     return i;
/*      */   }
/*      */   
/*      */   public final String getDTString()
/*      */   {
/*  503 */     String interval = "INTERVAL ";
/*      */     
/*      */ 
/*  506 */     switch (this.type) {
/*      */     case 3: 
/*  508 */       String dStr = String.valueOf(abs(this.days));
/*      */       
/*  510 */       if (this.days < 0) {
/*  511 */         interval = interval + "-";
/*      */       }
/*  513 */       if (dStr.length() < this.loadPrec) {
/*  514 */         int len = dStr.length();
/*  515 */         int destLen = this.loadPrec;
/*      */         
/*  517 */         while (destLen-- > len) {
/*  518 */           dStr = "0" + dStr;
/*      */         }
/*      */       }
/*      */       
/*  522 */       interval = interval + "'" + dStr + "' DAY(" + this.loadPrec + ")";
/*  523 */       break;
/*      */     case 4: 
/*  525 */       String dStr = String.valueOf(abs(this.days));
/*  526 */       String hStr = String.valueOf(abs(this.hours));
/*      */       
/*  528 */       if ((this.days < 0) || (this.hours < 0)) {
/*  529 */         interval = interval + "-";
/*      */       }
/*  531 */       if (dStr.length() < this.loadPrec) {
/*  532 */         int len = dStr.length();
/*  533 */         int destLen = this.loadPrec;
/*      */         
/*  535 */         while (destLen-- > len) {
/*  536 */           dStr = "0" + dStr;
/*      */         }
/*      */       }
/*      */       
/*  540 */       if (hStr.length() < 2) {
/*  541 */         hStr = "0" + hStr;
/*      */       }
/*      */       
/*  544 */       interval = 
/*  545 */         interval + "'" + dStr + " " + hStr + "' DAY(" + this.loadPrec + ") TO HOUR";
/*  546 */       break;
/*      */     case 5: 
/*  548 */       String dStr = String.valueOf(abs(this.days));
/*  549 */       String hStr = String.valueOf(abs(this.hours));
/*  550 */       String mStr = String.valueOf(abs(this.minutes));
/*      */       
/*  552 */       if ((this.days < 0) || (this.days < 0) || (this.minutes < 0)) {
/*  553 */         interval = interval + "-";
/*      */       }
/*  555 */       if (dStr.length() < this.loadPrec) {
/*  556 */         int len = dStr.length();
/*  557 */         int destLen = this.loadPrec;
/*      */         
/*  559 */         while (destLen-- > len) {
/*  560 */           dStr = "0" + dStr;
/*      */         }
/*      */       }
/*  563 */       if (hStr.length() < 2) {
/*  564 */         hStr = "0" + hStr;
/*      */       }
/*  566 */       if (mStr.length() < 2) {
/*  567 */         mStr = "0" + mStr;
/*      */       }
/*  569 */       interval = 
/*  570 */         interval + "'" + dStr + " " + hStr + ":" + mStr + "' DAY(" + this.loadPrec + ") TO MINUTE";
/*  571 */       break;
/*      */     case 6: 
/*  573 */       String dStr = String.valueOf(abs(this.days));
/*  574 */       String hStr = String.valueOf(abs(this.hours));
/*  575 */       String mStr = String.valueOf(abs(this.minutes));
/*  576 */       String sStr = String.valueOf(abs(this.seconds));
/*  577 */       String nStr = getMsecString();
/*  578 */       if ((this.days < 0) || (this.hours < 0) || (this.minutes < 0) || 
/*  579 */         (this.seconds < 0) || (this.fraction < 0)) {
/*  580 */         interval = interval + "-";
/*      */       }
/*      */       
/*  583 */       if (dStr.length() < this.loadPrec) {
/*  584 */         int len = dStr.length();
/*  585 */         int destLen = this.loadPrec;
/*      */         
/*  587 */         while (destLen-- > len) {
/*  588 */           dStr = "0" + dStr;
/*      */         }
/*      */       }
/*  591 */       if (hStr.length() < 2) {
/*  592 */         hStr = "0" + hStr;
/*      */       }
/*  594 */       if (mStr.length() < 2) {
/*  595 */         mStr = "0" + mStr;
/*      */       }
/*  597 */       if (sStr.length() < 2) {
/*  598 */         sStr = "0" + sStr;
/*      */       }
/*  600 */       interval = 
/*      */       
/*  602 */         interval + "'" + dStr + " " + hStr + ":" + mStr + ":" + sStr + "." + nStr + "' DAY(" + this.loadPrec + ") TO SECOND(" + this.secPrec + ")";
/*      */       
/*  604 */       break;
/*      */     case 7: 
/*  606 */       String hStr = String.valueOf(abs(this.hours));
/*  607 */       if (this.hours < 0) {
/*  608 */         interval = interval + "-";
/*      */       }
/*  610 */       if (hStr.length() < this.loadPrec) {
/*  611 */         int len = hStr.length();
/*  612 */         int destLen = this.loadPrec;
/*      */         
/*  614 */         while (destLen-- > len) {
/*  615 */           hStr = "0" + hStr;
/*      */         }
/*      */       }
/*      */       
/*  619 */       interval = interval + "'" + hStr + "' HOUR(" + this.loadPrec + ")";
/*  620 */       break;
/*      */     case 8: 
/*  622 */       String hStr = String.valueOf(abs(this.hours));
/*  623 */       String mStr = String.valueOf(abs(this.minutes));
/*      */       
/*  625 */       if ((this.hours < 0) || (this.minutes < 0)) {
/*  626 */         interval = interval + "-";
/*      */       }
/*  628 */       if (hStr.length() < this.loadPrec) {
/*  629 */         int len = hStr.length();
/*  630 */         int destLen = this.loadPrec;
/*      */         
/*  632 */         while (destLen-- > len) {
/*  633 */           hStr = "0" + hStr;
/*      */         }
/*      */       }
/*  636 */       if (mStr.length() < 2) {
/*  637 */         mStr = "0" + mStr;
/*      */       }
/*      */       
/*  640 */       interval = 
/*  641 */         interval + "'" + hStr + ":" + mStr + "' HOUR(" + this.loadPrec + ") TO MINUTE";
/*  642 */       break;
/*      */     case 9: 
/*  644 */       String nStr = getMsecString();
/*  645 */       String hStr = String.valueOf(abs(this.hours));
/*  646 */       String mStr = String.valueOf(abs(this.minutes));
/*  647 */       String sStr = String.valueOf(abs(this.seconds));
/*      */       
/*  649 */       if ((this.hours < 0) || (this.minutes < 0) || (this.seconds < 0) || 
/*  650 */         (this.fraction < 0)) {
/*  651 */         interval = interval + "-";
/*      */       }
/*      */       
/*  654 */       if (hStr.length() < this.loadPrec) {
/*  655 */         int len = hStr.length();
/*  656 */         int destLen = this.loadPrec;
/*      */         
/*  658 */         while (destLen-- > len) {
/*  659 */           hStr = "0" + hStr;
/*      */         }
/*      */       }
/*  662 */       if (mStr.length() < 2) {
/*  663 */         mStr = "0" + mStr;
/*      */       }
/*  665 */       if (sStr.length() < 2) {
/*  666 */         sStr = "0" + sStr;
/*      */       }
/*      */       
/*  669 */       interval = 
/*  670 */         interval + "'" + hStr + ":" + mStr + ":" + sStr + "." + nStr + "' HOUR(" + this.loadPrec + ") TO SECOND(" + this.secPrec + ")";
/*  671 */       break;
/*      */     case 10: 
/*  673 */       String mStr = String.valueOf(abs(this.minutes));
/*      */       
/*  675 */       if (this.minutes < 0) {
/*  676 */         interval = interval + "-";
/*      */       }
/*  678 */       if (mStr.length() < this.loadPrec) {
/*  679 */         int len = mStr.length();
/*  680 */         int destLen = this.loadPrec;
/*      */         
/*  682 */         while (destLen-- > len) {
/*  683 */           mStr = "0" + mStr;
/*      */         }
/*      */       }
/*      */       
/*  687 */       interval = interval + "'" + mStr + "' MINUTE(" + this.loadPrec + ")";
/*  688 */       break;
/*      */     case 11: 
/*  690 */       String nStr = getMsecString();
/*  691 */       String mStr = String.valueOf(abs(this.minutes));
/*  692 */       String sStr = String.valueOf(abs(this.seconds));
/*      */       
/*  694 */       if ((this.minutes < 0) || (this.seconds < 0) || (this.fraction < 0)) {
/*  695 */         interval = interval + "-";
/*      */       }
/*      */       
/*  698 */       if (mStr.length() < this.loadPrec) {
/*  699 */         int len = mStr.length();
/*  700 */         int destLen = this.loadPrec;
/*      */         
/*  702 */         while (destLen-- > len) {
/*  703 */           mStr = "0" + mStr;
/*      */         }
/*      */       }
/*  706 */       if (sStr.length() < 2) {
/*  707 */         sStr = "0" + sStr;
/*      */       }
/*  709 */       interval = 
/*  710 */         interval + "'" + mStr + ":" + sStr + "." + nStr + "' MINUTE(" + this.loadPrec + ") TO SECOND(" + this.secPrec + ")";
/*  711 */       break;
/*      */     case 12: 
/*  713 */       String nStr = getMsecString();
/*  714 */       String sStr = String.valueOf(abs(this.seconds));
/*      */       
/*  716 */       if ((this.seconds < 0) || (this.fraction < 0)) {
/*  717 */         interval = interval + "-";
/*      */       }
/*      */       
/*  720 */       if (sStr.length() < this.loadPrec) {
/*  721 */         int len = sStr.length();
/*  722 */         int destLen = this.loadPrec;
/*      */         
/*  724 */         while (destLen-- > len) {
/*  725 */           sStr = "0" + sStr;
/*      */         }
/*      */       }
/*      */       
/*  729 */       interval = 
/*  730 */         interval + "'" + sStr + "." + nStr + "' SECOND(" + this.loadPrec + "," + this.secPrec + ")";
/*      */     }
/*      */     
/*      */     
/*  734 */     return interval;
/*      */   }
/*      */   
/*      */   private String getMsecString() {
/*  738 */     String nano = abs(this.fraction);
/*      */     
/*  740 */     for (int i = 6 - nano.length(); i > 0; i--) {
/*  741 */       nano = "0" + nano;
/*      */     }
/*  743 */     if (nano.length() > this.secPrec) {
/*  744 */       nano = nano.substring(0, this.secPrec);
/*      */     }
/*  746 */     return nano;
/*      */   }
/*      */   
/*      */   public final String toString() {
/*  750 */     return getDTString();
/*      */   }
/*      */   
/*      */   public byte[] convertStrToBs(int prec) throws SQLException {
/*  754 */     int secPrec = prec & 0xF;
/*  755 */     int loadPrec = prec >> 4 & 0xF;
/*      */     
/*  757 */     checkPrec(loadPrec, secPrec);
/*      */     
/*  759 */     byte[] ym = new byte[24];
/*  760 */     System.arraycopy(Convertion.IntToByteArray(this.days), 0, ym, 0, 4);
/*  761 */     System.arraycopy(Convertion.IntToByteArray(this.hours), 0, ym, 4, 4);
/*  762 */     System.arraycopy(Convertion.IntToByteArray(this.minutes), 0, ym, 8, 4);
/*  763 */     System.arraycopy(Convertion.IntToByteArray(this.seconds), 0, ym, 12, 4);
/*  764 */     System.arraycopy(Convertion.IntToByteArray(this.fraction), 0, ym, 16, 4);
/*  765 */     System.arraycopy(Convertion.IntToByteArray(prec), 0, ym, 20, 4);
/*  766 */     return ym;
/*      */   }
/*      */   
/*      */   public void clear() {
/*  770 */     this.days = 0;
/*  771 */     this.hours = 0;
/*  772 */     this.minutes = 0;
/*  773 */     this.seconds = 0;
/*  774 */     this.fraction = 0;
/*      */   }
/*      */   
/*      */   private int getPrec(String str, boolean isLeadPrec) throws SQLException {
/*  778 */     if (isLeadPrec) {
/*  779 */       if (this.isLoadPrecSet) {
/*  780 */         return this.loadPrec;
/*      */       }
/*  782 */     } else if (this.isSecPrecSet) {
/*  783 */       return this.secPrec;
/*      */     }
/*      */     
/*  786 */     int leftBtId = -1;
/*  787 */     int rightBtId = -1;
/*  788 */     int prec = 0;
/*      */     
/*  790 */     leftBtId = str.indexOf("(");
/*  791 */     rightBtId = str.indexOf(")");
/*  792 */     if ((rightBtId == -1) && (leftBtId == -1)) {
/*  793 */       prec = isLeadPrec ? 2 : 6;
/*  794 */     } else if ((rightBtId != -1) && (leftBtId != -1) && (rightBtId > leftBtId + 1)) {
/*  795 */       String strPrec = str.substring(leftBtId + 1, rightBtId).trim();
/*  796 */       prec = Integer.parseInt(strPrec);
/*      */     } else {
/*  798 */       DBError.throwSQLException(6005);
/*      */     }
/*  800 */     return prec;
/*      */   }
/*      */   
/*      */   private void checkPrec(int loadPrec, int secPrec) throws SQLException {
/*  804 */     switch (this.type) {
/*      */     case 3: 
/*  806 */       if (loadPrec < String.valueOf(abs(this.days)).length())
/*  807 */         DBError.throwSQLException(6005);
/*  808 */       break;
/*      */     
/*      */     case 4: 
/*  811 */       if (loadPrec < String.valueOf(abs(this.days)).length())
/*  812 */         DBError.throwSQLException(6005);
/*  813 */       if (abs(this.hours) > 23)
/*  814 */         DBError.throwSQLException(6005);
/*  815 */       break;
/*      */     
/*      */     case 5: 
/*  818 */       if (loadPrec < String.valueOf(abs(this.days)).length())
/*  819 */         DBError.throwSQLException(6005);
/*  820 */       if ((abs(this.hours) > 23) || (abs(this.minutes) > 59))
/*  821 */         DBError.throwSQLException(6005);
/*  822 */       break;
/*      */     
/*      */     case 6: 
/*  825 */       if (loadPrec < String.valueOf(abs(this.days)).length())
/*  826 */         DBError.throwSQLException(6005);
/*  827 */       if ((abs(this.hours) > 23) || (abs(this.minutes) > 59) || 
/*  828 */         (abs(this.seconds) > 59))
/*  829 */         DBError.throwSQLException(6005);
/*  830 */       break;
/*      */     
/*      */     case 7: 
/*  833 */       if (loadPrec < String.valueOf(abs(this.hours)).length())
/*  834 */         DBError.throwSQLException(6005);
/*  835 */       break;
/*      */     
/*      */     case 8: 
/*  838 */       if (loadPrec < String.valueOf(abs(this.hours)).length())
/*  839 */         DBError.throwSQLException(6005);
/*  840 */       if (abs(this.minutes) > 59)
/*  841 */         DBError.throwSQLException(6005);
/*  842 */       break;
/*      */     
/*      */     case 9: 
/*  845 */       if (loadPrec < String.valueOf(abs(this.hours)).length())
/*  846 */         DBError.throwSQLException(6005);
/*  847 */       if ((abs(this.minutes) > 59) || (abs(this.seconds) > 59))
/*  848 */         DBError.throwSQLException(6005);
/*  849 */       break;
/*      */     
/*      */     case 10: 
/*  852 */       if (loadPrec < String.valueOf(abs(this.minutes)).length())
/*  853 */         DBError.throwSQLException(6005);
/*  854 */       break;
/*      */     
/*      */     case 11: 
/*  857 */       if (loadPrec < String.valueOf(abs(this.minutes)).length())
/*  858 */         DBError.throwSQLException(6005);
/*  859 */       if (abs(this.seconds) > 59)
/*  860 */         DBError.throwSQLException(6005);
/*  861 */       break;
/*      */     
/*      */     case 12: 
/*  864 */       if (loadPrec < String.valueOf(abs(this.seconds)).length()) {
/*  865 */         DBError.throwSQLException(6005);
/*      */       }
/*      */       break;
/*      */     }
/*      */   }
/*      */   
/*      */   private void setPrecForSvr(String leadPrec, String secPrec) throws SQLException {
/*  872 */     this.loadPrec = getPrec(leadPrec, true);
/*  873 */     this.secPrec = getPrec(secPrec, false);
/*      */     
/*  875 */     checkPrec(this.loadPrec, this.secPrec);
/*      */     
/*      */ 
/*  878 */     this.precForSvr = 
/*  879 */       ((this.type << 8) + (this.loadPrec << 4) + this.secPrec);
/*      */   }
/*      */   
/*      */   private String checkSign(String str)
/*      */     throws SQLException
/*      */   {
/*  885 */     int qindex = str.indexOf("'");
/*  886 */     int qlindex = str.lastIndexOf("'");
/*  887 */     if ((qindex == qlindex) || (qindex == -1)) {
/*  888 */       DBError.throwSQLException(6005);
/*      */     }
/*  890 */     int signIndex = str.lastIndexOf("-", qindex);
/*  891 */     if (signIndex != -1) {
/*  892 */       this.m_negative = true;
/*  893 */       str = str.replaceFirst("-", "");
/*      */     }
/*      */     
/*      */ 
/*  897 */     int signIndex2 = str.lastIndexOf("+", qindex);
/*  898 */     if ((signIndex != -1) && (signIndex2 != -1)) {
/*  899 */       DBError.throwSQLException(6005);
/*      */     }
/*  901 */     if (signIndex2 != -1) {
/*  902 */       this.m_negative = false;
/*  903 */       str = str.replaceFirst("+", "");
/*      */     }
/*      */     
/*  906 */     return str;
/*      */   }
/*      */   
/*      */   private void parseIntervDTString(String str) throws SQLException {
/*  910 */     if (str == null) {
/*  911 */       DBError.throwSQLException(6005);
/*      */     }
/*  913 */     str = str.toUpperCase().trim();
/*  914 */     String[] subStr = str.split(" ");
/*  915 */     if ((subStr.length < 3) || (!subStr[0].equalsIgnoreCase("INTERVAL"))) {
/*  916 */       DBError.throwSQLException(6005);
/*      */     }
/*      */     
/*  919 */     str = checkSign(str);
/*      */     
/*  921 */     String strLeadPrec = "";
/*  922 */     String strSecPrec = "";
/*      */     
/*  924 */     int leadPrecIndex = 0;
/*  925 */     int secPrecIndex = 0;
/*  926 */     int toIndex = 0;
/*      */     
/*  928 */     int valueIndex = str.indexOf(" ");
/*      */     
/*  930 */     String strvalue = null;
/*      */     
/*      */ 
/*  933 */     if ((leadPrecIndex = str.indexOf("DAY")) != -1) {
/*  934 */       toIndex = str.indexOf("TO", leadPrecIndex);
/*  935 */       strvalue = str.substring(valueIndex, leadPrecIndex).trim();
/*      */       
/*  937 */       if (toIndex == -1) {
/*  938 */         strLeadPrec = str.substring(leadPrecIndex).trim();
/*  939 */         setDay(strvalue);
/*      */       } else {
/*  941 */         strLeadPrec = str.substring(leadPrecIndex, toIndex).trim();
/*      */         
/*  943 */         if (str.indexOf("HOUR", toIndex) != -1) {
/*  944 */           setDayToHour(strvalue);
/*  945 */         } else if (str.indexOf("MINUTE", toIndex) != -1) {
/*  946 */           setDayToMinute(strvalue);
/*  947 */         } else if ((secPrecIndex = str.indexOf("SECOND", toIndex)) != -1) {
/*  948 */           strSecPrec = str.substring(secPrecIndex);
/*  949 */           setDayToSecond(strvalue);
/*      */         } else {
/*  951 */           DBError.throwSQLException(6005);
/*      */         }
/*      */       }
/*  954 */       setPrecForSvr(strLeadPrec, strSecPrec);
/*      */       
/*  956 */       return;
/*      */     }
/*      */     
/*      */ 
/*  960 */     if ((leadPrecIndex = str.indexOf("HOUR")) != -1) {
/*  961 */       toIndex = str.indexOf("TO", leadPrecIndex);
/*  962 */       strvalue = str.substring(valueIndex, leadPrecIndex).trim();
/*      */       
/*  964 */       if (toIndex == -1) {
/*  965 */         strLeadPrec = str.substring(leadPrecIndex);
/*  966 */         setHour(strvalue);
/*      */       } else {
/*  968 */         strLeadPrec = str.substring(leadPrecIndex, toIndex);
/*      */         
/*  970 */         if (str.indexOf("MINUTE", toIndex) != -1) {
/*  971 */           setHourToMinute(strvalue);
/*  972 */         } else if ((secPrecIndex = str.indexOf("SECOND", toIndex)) != -1) {
/*  973 */           strSecPrec = str.substring(secPrecIndex);
/*  974 */           setHourToSecond(strvalue);
/*      */         } else {
/*  976 */           DBError.throwSQLException(6005);
/*      */         }
/*      */       }
/*  979 */       setPrecForSvr(strLeadPrec, strSecPrec);
/*      */       
/*  981 */       return;
/*      */     }
/*      */     
/*      */ 
/*  985 */     if ((leadPrecIndex = str.indexOf("MINUTE")) != -1) {
/*  986 */       toIndex = str.indexOf("TO", leadPrecIndex);
/*  987 */       strvalue = str.substring(valueIndex, leadPrecIndex).trim();
/*      */       
/*  989 */       if (toIndex == -1) {
/*  990 */         strLeadPrec = str.substring(leadPrecIndex);
/*  991 */         setMinute(strvalue);
/*      */       } else {
/*  993 */         strLeadPrec = str.substring(leadPrecIndex, toIndex);
/*      */         
/*  995 */         if ((secPrecIndex = str.indexOf("SECOND", toIndex)) != -1) {
/*  996 */           strSecPrec = str.substring(secPrecIndex);
/*  997 */           setMinuteToSecond(strvalue);
/*      */         } else {
/*  999 */           DBError.throwSQLException(6005);
/*      */         }
/*      */       }
/* 1002 */       setPrecForSvr(strLeadPrec, strSecPrec);
/*      */       
/* 1004 */       return;
/*      */     }
/*      */     
/*      */ 
/* 1008 */     if ((leadPrecIndex = str.indexOf("SECOND")) != -1) {
/* 1009 */       strvalue = str.substring(valueIndex, leadPrecIndex).trim();
/* 1010 */       setSecond(strvalue);
/*      */       
/* 1012 */       strvalue = str.substring(leadPrecIndex).trim();
/*      */       
/* 1014 */       int colonIndex = strvalue.indexOf(",");
/* 1015 */       if (colonIndex == -1) {
/* 1016 */         strLeadPrec = strvalue;
/*      */       } else {
/* 1018 */         strLeadPrec = strvalue.substring(0, colonIndex).trim() + ")";
/* 1019 */         strSecPrec = "(" + strvalue.substring(colonIndex + 1).trim();
/*      */       }
/*      */       
/* 1022 */       setPrecForSvr(strLeadPrec, strSecPrec);
/*      */       
/* 1024 */       return;
/*      */     }
/*      */     
/* 1027 */     DBError.throwSQLException(6005);
/*      */   }
/*      */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\sql\DmdbIntervalDT.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */